// pages/shopOrderControl/orderDetail/orderDetail.js
import { orderDetail, onlineOrderList} from '../../../api.js'
let app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info_batchcode:'',//订单详情,
    orderInfo:[],
    status:0,
    type:'',// 1通知进入 
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('current_page',options)
    this.setData({
      info_batchcode:options.info_batchcode,
      status:options.status
    })
    if(options.type){
      this.setData({
        type:options.type
      })
    }
    orderDetail({ token: app.globalData.token, info_batchcode: options.info_batchcode,status:''}).then(res=>{
      if(res.data.code==666){
        this.setData({
          orderInfo: res.data.data[0]
        })
        if(res.data.data[0].sale_status==7){
          this.setData({
            'orderInfo.commodity_profit':0,
            'orderInfo.actual_profit':0
          })
        }
      } else if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function () {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }

    })

  },
  onShow(){

  },
  onUnload(){
    console.log('yincang')
    wx.setStorageSync('orderStatus', this.data.status)
  },
  returnPage(){
    wx.navigateBack({
      delta:1
    })
  },
  edit(e){
    let order_type=e.currentTarget.dataset.order_type;
    let info_batchcode=e.currentTarget.dataset.info_batchcode;
    wx.redirectTo({
      url: '/pages/goodControl/sell/sell?order_type='+order_type+'&info_batchcode='+info_batchcode+'&status='+this.data.status
    })
  },
})